package fecat.ui.contextpanel.order;

import java.util.Vector;

import fecat.entities.OrderModel;
import fecat.entities.QuoteModel;
import fecat.services.log.LoggingService;
import fecat.services.quote.QuoteService;
import fecat.ui.contextpanel.table.SortTotalTableData;
import fecat.util.common.OrderCommonString;

public class NewOrderTableData extends SortTotalTableData {
	public NewOrderTableData() {
		m_vector = new Vector<OrderModel>();
	}
	public OrderModel getOrderModelByRowIndex(int row){
		OrderModel om=(OrderModel)this.m_vector.get(row);
		return om;
	}
	public Object getValueAt(int nRow, int nCol) {
		if (nRow < 0 || nRow >= getRowCount())
			return "";
		if(nRow<m_vector.size()){
			OrderModel om=(OrderModel)this.m_vector.elementAt(nRow);
//			String[] values=this.getOrderDisplayValue(om);
			switch(nCol){
			case 0:
				return this.getOrderNo(om);
			case 1:
				return om.getAccountId();
			case 2:
				return om.getOwnerId();
			case 3:
				return OrderCommonString.getDisplayOrderTypeString(om.getOrderType());
			case 4:
				return om.getCurrency();
			case 5:
				return OrderCommonString.getShowBuySellString(om.getBuySellStatue());
			case 6:
				return om.getOrderLots();
			case 7:
				return this.getPrice(om);
			case 8:
				return this.getLimitPrice(om);
			case 9:
				return this.getStopPrice(om);
			case 10:
				return om.getUpdateTime();
			case 11:
				return om.getOperatorId();
			}
		}
		return "";
	}
	private String getOrderNo(OrderModel om){
		if(om.getOpenClose().equals("O")){
			return om.getOrderId();
		}
		else{
			return om.getOriginOrderNo();
		}
	}
	private String getPrice(OrderModel om){
		try{
			QuoteModel qm=QuoteService.getNewQuoteModel(om.getCurrency());
			if(om.getBuySellStatue().equals("B")){
				return String.valueOf(qm.getProperty("E"));
			}
			else{
				return String.valueOf(qm.getProperty("D"));
			}
		}
		catch(Exception ex){
			LoggingService.error(ex);
			return "";
		}
		
	}
	private String getLimitPrice(OrderModel om){
		String limitPrice="";
		if(om.getOpenClose().equals("O")){
			if(om.getOrderType().equals("L")){
				return om.getOpenLimitPrice();
			}
		}
		else{
			if(om.getOrderType().equals("L") || om.getOrderType().equals("O")){
				
				return om.getCloseLimitPrice();
			}
		}
		return "";
	}
	private String getStopPrice(OrderModel om){
		if(om.getOpenClose().equals("O")){
			if(om.getOrderType().equals("S")){
				return om.getOpenStopPrice();
			}
		}
		else{
			if(om.getOrderType().equals("S") || om.getOrderType().equals("O")){
				return om.getCloseStopPrice();
			}
		}
		return "";
	}
}
